home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1US4EOV (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  20.0 KB  |  772 lines

  1. package com.sun.java.swing.plaf.basic;
  2.  
  3. import com.sun.java.swing.JComponent;
  4. import com.sun.java.swing.JSlider;
  5. import com.sun.java.swing.KeyStroke;
  6. import com.sun.java.swing.LookAndFeel;
  7. import com.sun.java.swing.Timer;
  8. import com.sun.java.swing.UIManager;
  9. import com.sun.java.swing.plaf.ComponentUI;
  10. import com.sun.java.swing.plaf.SliderUI;
  11. import java.awt.Color;
  12. import java.awt.Component;
  13. import java.awt.Dimension;
  14. import java.awt.Graphics;
  15. import java.awt.IllegalComponentStateException;
  16. import java.awt.Insets;
  17. import java.awt.Polygon;
  18. import java.awt.Rectangle;
  19. import java.beans.PropertyChangeEvent;
  20. import java.beans.PropertyChangeListener;
  21. import java.io.Serializable;
  22. import java.util.Dictionary;
  23. import java.util.Enumeration;
  24.  
  25. public class BasicSliderUI extends SliderUI implements Serializable, PropertyChangeListener {
  26.    public final int POSITIVE_SCROLL = 1;
  27.    public final int NEGATIVE_SCROLL = -1;
  28.    public final int MIN_SCROLL = -2;
  29.    public final int MAX_SCROLL = 2;
  30.    protected ScrollListener scrollListener;
  31.    protected Timer scrollTimer;
  32.    protected JSlider slider;
  33.    protected Rectangle labelRect = new Rectangle(0, 0, 0, 0);
  34.    protected int trackBuffer = 0;
  35.    private static final int TICK_SPACE = 8;
  36.    private static final Dimension PREFERRED_HORIZONTAL_SIZE = new Dimension(164, 21);
  37.    private static final Dimension PREFERRED_VERTICAL_SIZE = new Dimension(21, 164);
  38.    private static final Dimension MINIMUM_HORIZONTAL_SIZE = new Dimension(36, 21);
  39.    private static final Dimension MINIMUM_VERTICAL_SIZE = new Dimension(21, 36);
  40.    private transient boolean isDragging;
  41.    private TrackListener trackListener;
  42.    private ModelListener modelListener;
  43.    private SizingListener sizeListener;
  44.    private FListener focusListener;
  45.    private Rectangle thumbRect = new Rectangle(0, 0, 0, 0);
  46.    private Color shadowColor;
  47.    private Color highlightColor;
  48.    private Color focusColor;
  49.  
  50.    public BasicSliderUI(JSlider b) {
  51.    }
  52.  
  53.    public void calculateThumbBounds() {
  54.       if (this.slider.getOrientation() == 1) {
  55.          this.setThumbBounds(this.getScrollTrackRect().x, this.yPositionForValue(this.slider.getValue()) - this.getThumbRect().height / 2, this.getScrollTrackRect().width, 11);
  56.       } else {
  57.          this.setThumbBounds(this.xPositionForValue(this.slider.getValue()) - this.getThumbRect().width / 2, this.getScrollTrackRect().y, 11, this.getScrollTrackRect().height);
  58.       }
  59.  
  60.    }
  61.  
  62.    public static ComponentUI createUI(JComponent b) {
  63.       return new BasicSliderUI((JSlider)b);
  64.    }
  65.  
  66.    public Color getFocusColor() {
  67.       return this.focusColor;
  68.    }
  69.  
  70.    protected Rectangle getFullContentArea() {
  71.       Rectangle r = new Rectangle();
  72.       Insets insets = this.slider.getInsets();
  73.       Dimension size = this.slider.getSize();
  74.       r.x = insets.left;
  75.       r.y = insets.top;
  76.       r.width = size.width - (insets.left + insets.right);
  77.       r.height = size.height - (insets.top + insets.bottom);
  78.       return r;
  79.    }
  80.  
  81.    protected int getHeightOfHighValueLabel() {
  82.       Component label = this.getHighestValueLabel();
  83.       int height = 0;
  84.       if (label != null) {
  85.          height = label.getPreferredSize().height;
  86.       }
  87.  
  88.       return height;
  89.    }
  90.  
  91.    protected int getHeightOfLowValueLabel() {
  92.       Component label = this.getLowestValueLabel();
  93.       int height = 0;
  94.       if (label != null) {
  95.          height = label.getPreferredSize().height;
  96.       }
  97.  
  98.       return height;
  99.    }
  100.  
  101.    protected int getHeightOfTallestLabel() {
  102.       Dictionary dictionary = this.slider.getLabelTable();
  103.       int tallest = 0;
  104.       Component label;
  105.       if (dictionary != null) {
  106.          for(Enumeration keys = dictionary.keys(); keys.hasMoreElements(); tallest = Math.max(label.getPreferredSize().height, tallest)) {
  107.             label = (Component)dictionary.get(keys.nextElement());
  108.          }
  109.       }
  110.  
  111.       return tallest;
  112.    }
  113.  
  114.    protected Component getHighestValueLabel() {
  115.       Dictionary dictionary = this.slider.getLabelTable();
  116.       Component label = null;
  117.       if (dictionary != null) {
  118.          Enumeration keys = dictionary.keys();
  119.          if (keys.hasMoreElements()) {
  120.             int highestValue;
  121.             int value;
  122.             for(highestValue = (Integer)keys.nextElement(); keys.hasMoreElements(); highestValue = Math.max(value, highestValue)) {
  123.                value = (Integer)keys.nextElement();
  124.             }
  125.  
  126.             label = (Component)dictionary.get(new Integer(highestValue));
  127.          }
  128.       }
  129.  
  130.       return label;
  131.    }
  132.  
  133.    public Color getHighlightColor() {
  134.       return this.highlightColor;
  135.    }
  136.  
  137.    public Rectangle getLabelRect() {
  138.       return this.labelRect;
  139.    }
  140.  
  141.    protected Component getLowestValueLabel() {
  142.       Dictionary dictionary = this.slider.getLabelTable();
  143.       Component label = null;
  144.       if (dictionary != null) {
  145.          Enumeration keys = dictionary.keys();
  146.          if (keys.hasMoreElements()) {
  147.             int lowestValue;
  148.             int value;
  149.             for(lowestValue = (Integer)keys.nextElement(); keys.hasMoreElements(); lowestValue = Math.min(value, lowestValue)) {
  150.                value = (Integer)keys.nextElement();
  151.             }
  152.  
  153.             label = (Component)dictionary.get(new Integer(lowestValue));
  154.          }
  155.       }
  156.  
  157.       return label;
  158.    }
  159.  
  160.    public Dimension getMaximumSize(JComponent c) {
  161.       Dimension d = this.getPreferredSize(c);
  162.       if (this.slider.getOrientation() == 1) {
  163.          d.height = 32767;
  164.       } else {
  165.          d.width = 32767;
  166.       }
  167.  
  168.       return d;
  169.    }
  170.  
  171.    public Dimension getMinimumHorizontalSize() {
  172.       return MINIMUM_HORIZONTAL_SIZE;
  173.    }
  174.  
  175.    public Dimension getMinimumSize(JComponent c) {
  176.       Dimension d;
  177.       if (this.slider.getOrientation() == 1) {
  178.          d = new Dimension(this.getMinimumVerticalSize());
  179.          if (this.slider.getPaintTicks()) {
  180.             d.width += this.getTickSpace() + 1;
  181.          }
  182.  
  183.          if (this.slider.getPaintLabels()) {
  184.             d.width += this.getLabelRect().width + 1;
  185.          }
  186.       } else {
  187.          d = new Dimension(this.getMinimumHorizontalSize());
  188.          if (this.slider.getPaintTicks()) {
  189.             d.height += this.getTickSpace() + 1;
  190.          }
  191.  
  192.          if (this.slider.getPaintLabels()) {
  193.             d.height += this.getLabelRect().height + 1;
  194.          }
  195.       }
  196.  
  197.       d.width += this.slider.getInsets().left + this.slider.getInsets().right;
  198.       d.height += this.slider.getInsets().top + this.slider.getInsets().bottom;
  199.       return d;
  200.    }
  201.  
  202.    public Dimension getMinimumVerticalSize() {
  203.       return MINIMUM_VERTICAL_SIZE;
  204.    }
  205.  
  206.    public Dimension getPreferredHorizontalSize() {
  207.       return PREFERRED_HORIZONTAL_SIZE;
  208.    }
  209.  
  210.    public Dimension getPreferredSize(JComponent c) {
  211.       Dimension d;
  212.       if (this.slider.getOrientation() == 1) {
  213.          d = new Dimension(this.getPreferredVerticalSize());
  214.          if (this.slider.getPaintTicks()) {
  215.             d.width += this.getScrollTickRect().width + 1;
  216.          }
  217.  
  218.          if (this.slider.getPaintLabels()) {
  219.             d.width += this.getLabelRect().width + 1;
  220.          }
  221.       } else {
  222.          d = new Dimension(this.getPreferredHorizontalSize());
  223.          if (this.slider.getPaintTicks()) {
  224.             d.height += this.getScrollTickRect().height + 1;
  225.          }
  226.  
  227.          if (this.slider.getPaintLabels()) {
  228.             d.height += this.getLabelRect().height + 1;
  229.          }
  230.       }
  231.  
  232.       d.width += this.slider.getInsets().left + this.slider.getInsets().right;
  233.       d.height += this.slider.getInsets().top + this.slider.getInsets().bottom;
  234.       return d;
  235.    }
  236.  
  237.    public Dimension getPreferredVerticalSize() {
  238.       return PREFERRED_VERTICAL_SIZE;
  239.    }
  240.  
  241.    public Rectangle getScrollTickRect() {
  242.       Rectangle r = this.getFullContentArea();
  243.       if (this.slider.getPaintTicks()) {
  244.          Rectangle labelRect = this.getLabelRect();
  245.          if (this.slider.getOrientation() == 1) {
  246.             if (this.slider.getPaintLabels()) {
  247.                r.setLocation(labelRect.x - 1 - this.getTickSize(), r.y);
  248.             } else {
  249.                r.setLocation(r.x + (r.width - 1) - this.getTickSize(), r.y);
  250.             }
  251.  
  252.             r.setSize(this.getTickSize(), r.height);
  253.          } else {
  254.             if (this.slider.getPaintLabels()) {
  255.                r.setLocation(r.x, labelRect.y - 1 - this.getTickSize());
  256.             } else {
  257.                r.setLocation(r.x, r.y + (r.height - 1) - this.getTickSize());
  258.             }
  259.  
  260.             r.setSize(r.width, this.getTickSize());
  261.          }
  262.       } else {
  263.          r.setLocation(this.labelRect.x, this.labelRect.y);
  264.          if (this.slider.getOrientation() == 1) {
  265.             r.setSize(0, r.height);
  266.          } else {
  267.             r.setSize(r.width, 0);
  268.          }
  269.       }
  270.  
  271.       return r;
  272.    }
  273.  
  274.    public Rectangle getScrollTrackRect() {
  275.       Rectangle r = this.getFullContentArea();
  276.       if (this.slider.getPaintTicks() || this.slider.getPaintLabels()) {
  277.          if (this.slider.getOrientation() == 0) {
  278.             r.setSize(r.width, this.getScrollTickRect().y - 1 - r.y);
  279.          } else {
  280.             r.setSize(this.getScrollTickRect().x - 1 - r.x, r.height);
  281.          }
  282.       }
  283.  
  284.       return r;
  285.    }
  286.  
  287.    public Color getShadowColor() {
  288.       return this.shadowColor;
  289.    }
  290.  
  291.    public Rectangle getThumbRect() {
  292.       return this.thumbRect;
  293.    }
  294.  
  295.    public int getTickSize() {
  296.       return this.getTickSpace();
  297.    }
  298.  
  299.    public int getTickSpace() {
  300.       return 8;
  301.    }
  302.  
  303.    protected int getWidthOfHighValueLabel() {
  304.       Component label = this.getHighestValueLabel();
  305.       int width = 0;
  306.       if (label != null) {
  307.          width = label.getPreferredSize().width;
  308.       }
  309.  
  310.       return width;
  311.    }
  312.  
  313.    protected int getWidthOfLowValueLabel() {
  314.       Component label = this.getLowestValueLabel();
  315.       int width = 0;
  316.       if (label != null) {
  317.          width = label.getPreferredSize().width;
  318.       }
  319.  
  320.       return width;
  321.    }
  322.  
  323.    protected int getWidthOfWidestLabel() {
  324.       Dictionary dictionary = this.slider.getLabelTable();
  325.       int widest = 0;
  326.       Component label;
  327.       if (dictionary != null) {
  328.          for(Enumeration keys = dictionary.keys(); keys.hasMoreElements(); widest = Math.max(label.getPreferredSize().width, widest)) {
  329.             label = (Component)dictionary.get(keys.nextElement());
  330.          }
  331.       }
  332.  
  333.       return widest;
  334.    }
  335.  
  336.    public void installUI(JComponent c) {
  337.       this.slider = (JSlider)c;
  338.       LookAndFeel.installBorder(this.slider, "Slider.border");
  339.       LookAndFeel.installColors(this.slider, "Slider.background", "Slider.foreground");
  340.       this.highlightColor = UIManager.getColor("Slider.highlight");
  341.       this.shadowColor = UIManager.getColor("Slider.shadow");
  342.       this.focusColor = UIManager.getColor("Slider.focus");
  343.       this.isDragging = false;
  344.       this.trackListener = new TrackListener(this);
  345.       this.modelListener = new ModelListener(this);
  346.       this.sizeListener = new SizingListener(this);
  347.       this.focusListener = new FListener(this);
  348.       this.scrollListener = new ScrollListener(this);
  349.       this.scrollTimer = new Timer(100, this.scrollListener);
  350.       this.scrollTimer.setInitialDelay(300);
  351.       this.slider.addMouseListener(this.trackListener);
  352.       this.slider.addMouseMotionListener(this.trackListener);
  353.       this.slider.addFocusListener(this.focusListener);
  354.       this.slider.addComponentListener(this.sizeListener);
  355.       this.slider.addPropertyChangeListener(this);
  356.       this.slider.getModel().addChangeListener(this.modelListener);
  357.       this.slider.setEnabled(this.slider.isEnabled());
  358.       this.slider.setOpaque(true);
  359.       this.calculateThumbBounds();
  360.       this.recalcLabelRect();
  361.       this.recalcTrackBuffer();
  362.       this.calculateThumbBounds();
  363.       this.slider.registerKeyboardAction(new ActionScroller(this, this.slider, 1, false), KeyStroke.getKeyStroke(39, 0), 0);
  364.       this.slider.registerKeyboardAction(new ActionScroller(this, this.slider, -1, false), KeyStroke.getKeyStroke(40, 0), 0);
  365.       this.slider.registerKeyboardAction(new ActionScroller(this, this.slider, -1, true), KeyStroke.getKeyStroke(34, 0), 0);
  366.       this.slider.registerKeyboardAction(new ActionScroller(this, this.slider, -1, false), KeyStroke.getKeyStroke(37, 0), 0);
  367.       this.slider.registerKeyboardAction(new ActionScroller(this, this.slider, 1, false), KeyStroke.getKeyStroke(38, 0), 0);
  368.       this.slider.registerKeyboardAction(new ActionScroller(this, this.slider, 1, true), KeyStroke.getKeyStroke(33, 0), 0);
  369.       this.slider.registerKeyboardAction(new ActionScroller(this, this.slider, -2, true), KeyStroke.getKeyStroke(36, 0), 0);
  370.       this.slider.registerKeyboardAction(new ActionScroller(this, this.slider, 2, true), KeyStroke.getKeyStroke(35, 0), 0);
  371.    }
  372.  
  373.    public void paint(Graphics g, JComponent c) {
  374.       this.paintTrack(g);
  375.       if (this.slider.getPaintTicks()) {
  376.          this.paintTicks(g);
  377.       }
  378.  
  379.       if (this.slider.getPaintLabels()) {
  380.          this.paintLabels(g);
  381.       }
  382.  
  383.       this.paintFocus(g);
  384.       this.paintThumb(g);
  385.    }
  386.  
  387.    public void paintFocus(Graphics g) {
  388.       if (this.slider.hasFocus()) {
  389.          Rectangle r = this.slider.getBounds();
  390.          r.x = 0;
  391.          r.y = 0;
  392.          if (this.slider.getBorder() != null) {
  393.             r = this.getFullContentArea();
  394.          }
  395.  
  396.          g.setColor(this.getFocusColor());
  397.          BasicGraphicsUtils.drawDashedRect(g, r.x + 1, r.y + 1, r.width - 2, r.height - 2);
  398.       }
  399.  
  400.    }
  401.  
  402.    protected void paintHorizontalLabel(Graphics g, int value, Component label) {
  403.       int labelCenter = this.xPositionForValue(value);
  404.       int labelLeft = labelCenter - label.getPreferredSize().width / 2;
  405.       g.translate(labelLeft, 0);
  406.       label.paint(g);
  407.       g.translate(-labelLeft, 0);
  408.    }
  409.  
  410.    public void paintLabels(Graphics g) {
  411.       Rectangle labelBounds = this.getLabelRect();
  412.       g.translate(labelBounds.x, labelBounds.y);
  413.       Dictionary dictionary = this.slider.getLabelTable();
  414.       if (dictionary != null) {
  415.          Enumeration keys = dictionary.keys();
  416.  
  417.          while(keys.hasMoreElements()) {
  418.             Integer key = (Integer)keys.nextElement();
  419.             Component label = (Component)dictionary.get(key);
  420.             if (this.slider.getOrientation() == 0) {
  421.                this.paintHorizontalLabel(g, key, label);
  422.             } else {
  423.                this.paintVerticalLabel(g, key, label);
  424.             }
  425.          }
  426.       }
  427.  
  428.       g.translate(-labelBounds.x, -labelBounds.y);
  429.    }
  430.  
  431.    protected void paintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x) {
  432.       g.drawLine(x, 0, x, tickBounds.height - 2);
  433.    }
  434.  
  435.    protected void paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y) {
  436.       g.drawLine(0, y, tickBounds.width - 2, y);
  437.    }
  438.  
  439.    protected void paintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x) {
  440.       g.drawLine(x, 0, x, tickBounds.height / 2 - 1);
  441.    }
  442.  
  443.    protected void paintMinorTickForVertSlider(Graphics g, Rectangle tickBounds, int y) {
  444.       g.drawLine(0, y, tickBounds.width / 2 - 1, y);
  445.    }
  446.  
  447.    public void paintThumb(Graphics g) {
  448.       Rectangle knobBounds = this.getThumbRect();
  449.       int w = knobBounds.width;
  450.       int h = knobBounds.height;
  451.       g.translate(knobBounds.x, knobBounds.y);
  452.       if (this.slider.isEnabled()) {
  453.          g.setColor(this.slider.getBackground());
  454.       } else {
  455.          g.setColor(this.slider.getBackground().darker());
  456.       }
  457.  
  458.       if (!this.slider.getPaintTicks()) {
  459.          g.fillRect(0, 0, w, h);
  460.          g.setColor(Color.black);
  461.          g.drawLine(0, h - 1, w - 1, h - 1);
  462.          g.drawLine(w - 1, 0, w - 1, h - 1);
  463.          g.setColor(BasicGraphicsUtils.controlHighlight);
  464.          g.drawLine(0, 0, 0, h - 2);
  465.          g.drawLine(1, 0, w - 2, 0);
  466.          g.setColor(BasicGraphicsUtils.controlShadow);
  467.          g.drawLine(1, h - 2, w - 2, h - 2);
  468.          g.drawLine(w - 2, 1, w - 2, h - 3);
  469.       } else if (this.slider.getOrientation() == 0) {
  470.          int cw = w / 2;
  471.          g.fillRect(1, 1, w - 3, h - 1 - cw);
  472.          Polygon p = new Polygon();
  473.          p.addPoint(1, h - cw);
  474.          p.addPoint(cw - 1, h - 1);
  475.          p.addPoint(w - 2, h - 1 - cw);
  476.          g.fillPolygon(p);
  477.          g.setColor(BasicGraphicsUtils.controlHighlight);
  478.          g.drawLine(0, 0, w - 2, 0);
  479.          g.drawLine(0, 1, 0, h - 1 - cw);
  480.          g.drawLine(0, h - cw, cw - 1, h - 1);
  481.          g.setColor(Color.black);
  482.          g.drawLine(w - 1, 0, w - 1, h - 2 - cw);
  483.          g.drawLine(w - 1, h - 1 - cw, w - 1 - cw, h - 1);
  484.          g.setColor(BasicGraphicsUtils.controlShadow);
  485.          g.drawLine(w - 2, 1, w - 2, h - 2 - cw);
  486.          g.drawLine(w - 2, h - 1 - cw, w - 1 - cw, h - 2);
  487.       } else {
  488.          int cw = h / 2;
  489.          g.fillRect(1, 1, w - 1 - cw, h - 3);
  490.          Polygon p = new Polygon();
  491.          p.addPoint(w - cw - 1, 0);
  492.          p.addPoint(w - 1, cw);
  493.          p.addPoint(w - 1 - cw, h - 2);
  494.          g.fillPolygon(p);
  495.          g.setColor(BasicGraphicsUtils.controlHighlight);
  496.          g.drawLine(0, 0, 0, h - 2);
  497.          g.drawLine(1, 0, w - 1 - cw, 0);
  498.          g.drawLine(w - cw - 1, 0, w - 1, cw);
  499.          g.setColor(Color.black);
  500.          g.drawLine(0, h - 1, w - 2 - cw, h - 1);
  501.          g.drawLine(w - 1 - cw, h - 1, w - 1, h - 1 - cw);
  502.          g.setColor(BasicGraphicsUtils.controlShadow);
  503.          g.drawLine(1, h - 2, w - 2 - cw, h - 2);
  504.          g.drawLine(w - 1 - cw, h - 2, w - 2, h - cw - 1);
  505.       }
  506.  
  507.       g.translate(-knobBounds.x, -knobBounds.y);
  508.    }
  509.  
  510.    public void paintTicks(Graphics g) {
  511.       Rectangle tickBounds = this.getScrollTickRect();
  512.       int var10000 = tickBounds.width;
  513.       var10000 = tickBounds.height;
  514.       g.translate(tickBounds.x, tickBounds.y);
  515.       g.setColor(this.slider.getBackground());
  516.       g.fillRect(0, 0, tickBounds.width, tickBounds.height);
  517.       g.setColor(Color.black);
  518.       this.slider.getMajorTickSpacing();
  519.       this.slider.getMinorTickSpacing();
  520.       if (this.slider.getOrientation() == 0) {
  521.          int value = this.slider.getMinimum();
  522.          int xPos = 0;
  523.          if (this.slider.getMinorTickSpacing() > 0) {
  524.             while(value <= this.slider.getMaximum()) {
  525.                xPos = this.xPositionForValue(value);
  526.                this.paintMinorTickForHorizSlider(g, tickBounds, xPos);
  527.                value += this.slider.getMinorTickSpacing();
  528.             }
  529.          }
  530.  
  531.          if (this.slider.getMajorTickSpacing() > 0) {
  532.             for(int var5 = this.slider.getMinimum(); var5 <= this.slider.getMaximum(); var5 += this.slider.getMajorTickSpacing()) {
  533.                xPos = this.xPositionForValue(var5);
  534.                this.paintMajorTickForHorizSlider(g, tickBounds, xPos);
  535.             }
  536.          }
  537.       } else {
  538.          int value = this.slider.getMinimum();
  539.          int yPos = 0;
  540.          if (this.slider.getMinorTickSpacing() > 0) {
  541.             while(value <= this.slider.getMaximum()) {
  542.                yPos = this.yPositionForValue(value);
  543.                this.paintMinorTickForVertSlider(g, tickBounds, yPos);
  544.                value += this.slider.getMinorTickSpacing();
  545.             }
  546.          }
  547.  
  548.          if (this.slider.getMajorTickSpacing() > 0) {
  549.             for(int var7 = this.slider.getMinimum(); var7 <= this.slider.getMaximum(); var7 += this.slider.getMajorTickSpacing()) {
  550.                yPos = this.yPositionForValue(var7);
  551.                this.paintMajorTickForVertSlider(g, tickBounds, yPos);
  552.             }
  553.          }
  554.       }
  555.  
  556.       g.translate(-tickBounds.x, -tickBounds.y);
  557.    }
  558.  
  559.    public void paintTrack(Graphics g) {
  560.       Rectangle trackBounds = this.getScrollTrackRect();
  561.       int cx;
  562.       int cy;
  563.       if (this.slider.getOrientation() == 0) {
  564.          int pad = this.trackBuffer;
  565.          cx = pad;
  566.          cy = trackBounds.height / 2 - 2;
  567.          int cw = trackBounds.width - this.trackBuffer * 2;
  568.          g.translate(trackBounds.x + pad, trackBounds.y + cy);
  569.          g.setColor(this.getShadowColor());
  570.          g.drawLine(0, 0, cw - 1, 0);
  571.          g.drawLine(0, 1, 0, 2);
  572.          g.setColor(this.getHighlightColor());
  573.          g.drawLine(0, 3, cw, 3);
  574.          g.drawLine(cw, 0, cw, 3);
  575.          g.setColor(Color.black);
  576.          g.drawLine(1, 1, cw - 2, 1);
  577.       } else {
  578.          int var8 = this.trackBuffer;
  579.          cx = trackBounds.width / 2 - 2;
  580.          cy = var8;
  581.          int ch = trackBounds.height - this.trackBuffer * 2;
  582.          g.translate(trackBounds.x + cx, trackBounds.y + var8);
  583.          g.setColor(this.getShadowColor());
  584.          g.drawLine(0, 0, 0, ch - 1);
  585.          g.drawLine(1, 0, 2, 0);
  586.          g.setColor(this.getHighlightColor());
  587.          g.drawLine(3, 0, 3, ch);
  588.          g.drawLine(0, ch, 3, ch);
  589.          g.setColor(Color.black);
  590.          g.drawLine(1, 1, 1, ch - 2);
  591.       }
  592.  
  593.       g.translate(-(trackBounds.x + cx), -(trackBounds.y + cy));
  594.    }
  595.  
  596.    protected void paintVerticalLabel(Graphics g, int value, Component label) {
  597.       int labelCenter = this.yPositionForValue(value);
  598.       int labelTop = labelCenter - label.getPreferredSize().height / 2;
  599.       g.translate(0, labelTop);
  600.       label.paint(g);
  601.       g.translate(0, -labelTop);
  602.    }
  603.  
  604.    public void propertyChange(PropertyChangeEvent evt) {
  605.       if (evt.getPropertyName().equals("labelTable")) {
  606.          this.recalcLabelRect();
  607.          this.recalcTrackBuffer();
  608.       }
  609.  
  610.    }
  611.  
  612.    protected void recalcLabelRect() {
  613.       Rectangle interior = this.getFullContentArea();
  614.       if (this.slider.getPaintLabels()) {
  615.          if (this.slider.getOrientation() == 0) {
  616.             int maxLabelHeight = this.getHeightOfTallestLabel();
  617.             interior.y = interior.y + (interior.height - 1) - maxLabelHeight;
  618.             interior.height = maxLabelHeight;
  619.          } else {
  620.             int maxLabelWidth = this.getWidthOfWidestLabel();
  621.             interior.x = interior.x + (interior.width - 1) - maxLabelWidth;
  622.             interior.width = maxLabelWidth;
  623.          }
  624.       } else if (this.slider.getOrientation() == 1) {
  625.          interior.setLocation(interior.x + (interior.width - 1), interior.y);
  626.          interior.setSize(0, interior.height);
  627.       } else {
  628.          interior.setLocation(interior.x, interior.y + (interior.height - 1));
  629.          interior.setSize(interior.width, 0);
  630.       }
  631.  
  632.       this.labelRect = interior;
  633.    }
  634.  
  635.    protected void recalcTrackBuffer() {
  636.       if (this.slider.getPaintLabels() && this.slider.getLabelTable() != null) {
  637.          Component highLabel = this.getHighestValueLabel();
  638.          Component lowLabel = this.getLowestValueLabel();
  639.          if (this.slider.getOrientation() == 0) {
  640.             this.trackBuffer = Math.max(highLabel.getBounds().width, lowLabel.getBounds().width) / 2;
  641.             this.trackBuffer = Math.max(this.trackBuffer, this.getThumbRect().width / 2);
  642.          } else {
  643.             this.trackBuffer = Math.max(highLabel.getBounds().height, lowLabel.getBounds().height) / 2;
  644.             this.trackBuffer = Math.max(this.trackBuffer, this.getThumbRect().height / 2);
  645.          }
  646.       } else if (this.slider.getOrientation() == 0) {
  647.          this.trackBuffer = this.getThumbRect().width / 2;
  648.       } else {
  649.          this.trackBuffer = this.getThumbRect().height / 2;
  650.       }
  651.  
  652.    }
  653.  
  654.    public void scrollByBlock(int direction) {
  655.       synchronized(this.slider){}
  656.  
  657.       try {
  658.          int oldValue = this.slider.getValue();
  659.          int blockIncrement = this.slider.getMaximum() / 10;
  660.          int delta = blockIncrement * (direction > 0 ? 1 : -1);
  661.          this.slider.setValue(oldValue + delta);
  662.       } catch (Throwable var7) {
  663.          throw var7;
  664.       }
  665.  
  666.    }
  667.  
  668.    public void scrollByUnit(int direction) {
  669.       synchronized(this.slider){}
  670.  
  671.       try {
  672.          int oldValue = this.slider.getValue();
  673.          int delta = 1 * (direction > 0 ? 1 : -1);
  674.          this.slider.setValue(oldValue + delta);
  675.       } catch (Throwable var6) {
  676.          throw var6;
  677.       }
  678.  
  679.    }
  680.  
  681.    protected void scrollDueToClickInTrack(int dir) {
  682.       this.scrollByBlock(dir);
  683.    }
  684.  
  685.    public void setThumbBounds(int x, int y, int width, int height) {
  686.       Rectangle r = new Rectangle(this.thumbRect.x, this.thumbRect.y, this.thumbRect.width, this.thumbRect.height);
  687.       this.thumbRect.setBounds(x, y, width, height);
  688.       Rectangle r2 = r.union(this.thumbRect);
  689.       this.slider.repaint(r2.x, r2.y, r2.width, r2.height);
  690.    }
  691.  
  692.    public void setThumbLocation(int x, int y) {
  693.       Rectangle r = new Rectangle(this.thumbRect.x, this.thumbRect.y, this.thumbRect.width, this.thumbRect.height);
  694.       this.thumbRect.setLocation(x, y);
  695.       Rectangle r2 = r.union(this.thumbRect);
  696.       this.slider.repaint(r2.x, r2.y, r2.width, r2.height);
  697.    }
  698.  
  699.    public void uninstallUI(JComponent c) {
  700.       if (c != this.slider) {
  701.          throw new IllegalComponentStateException(this + " was asked to deinstall() " + c + " when it only knows about " + this.slider + ".");
  702.       } else {
  703.          LookAndFeel.uninstallBorder(this.slider);
  704.          this.scrollTimer.stop();
  705.          this.scrollTimer = null;
  706.          this.slider.getModel().removeChangeListener(this.modelListener);
  707.          this.slider.removeMouseListener(this.trackListener);
  708.          this.slider.removeMouseMotionListener(this.trackListener);
  709.          this.slider.removeFocusListener(this.focusListener);
  710.          this.slider.removeComponentListener(this.sizeListener);
  711.          this.slider.removePropertyChangeListener(this);
  712.          this.slider.resetKeyboardActions();
  713.          this.thumbRect = null;
  714.          this.slider = null;
  715.       }
  716.    }
  717.  
  718.    protected int xPositionForValue(int randomValue) {
  719.       int min = this.slider.getMinimum();
  720.       this.slider.getMaximum();
  721.       Rectangle trackRect = this.getScrollTrackRect();
  722.       int trackLength = trackRect.width - this.trackBuffer * 2;
  723.       int valueRange = this.slider.getMaximum() - this.slider.getMinimum();
  724.       double pixelsPerValue = (double)trackLength / (double)valueRange;
  725.       int trackLeft = trackRect.x + this.trackBuffer;
  726.       int trackRight = trackRect.x + (trackRect.width - 1) - this.trackBuffer;
  727.       int xPosition;
  728.       if (!this.slider.getInverted()) {
  729.          xPosition = (int)((long)trackLeft + Math.round(pixelsPerValue * (double)(randomValue - min)));
  730.       } else {
  731.          xPosition = (int)((long)trackRight - Math.round(pixelsPerValue * (double)(randomValue - min)));
  732.       }
  733.  
  734.       xPosition = Math.max(trackLeft, xPosition);
  735.       xPosition = Math.min(trackRight, xPosition);
  736.       return xPosition;
  737.    }
  738.  
  739.    protected int yPositionForValue(int randomValue) {
  740.       int min = this.slider.getMinimum();
  741.       int max = this.slider.getMaximum();
  742.       Rectangle trackRect = this.getScrollTrackRect();
  743.       int trackLength = trackRect.height - this.trackBuffer * 2;
  744.       int valueRange = this.slider.getMaximum() - this.slider.getMinimum();
  745.       double pixelsPerValue = (double)trackLength / (double)valueRange;
  746.       int trackTop = trackRect.y + this.trackBuffer;
  747.       int trackBottom = trackRect.y + (trackRect.height - 1) - this.trackBuffer;
  748.       int yPosition;
  749.       if (!this.slider.getInverted()) {
  750.          yPosition = (int)((long)trackTop + Math.round(pixelsPerValue * (double)(max - randomValue)));
  751.       } else {
  752.          yPosition = (int)((long)trackTop + Math.round(pixelsPerValue * (double)(randomValue - min)));
  753.       }
  754.  
  755.       yPosition = Math.max(trackTop, yPosition);
  756.       yPosition = Math.min(trackBottom, yPosition);
  757.       return yPosition;
  758.    }
  759.  
  760.    static TrackListener access$trackListener(BasicSliderUI var0) {
  761.       return var0.trackListener;
  762.    }
  763.  
  764.    static boolean access$isDragging(BasicSliderUI var0) {
  765.       return var0.isDragging;
  766.    }
  767.  
  768.    static void access$isDragging(BasicSliderUI var0, boolean var1) {
  769.       var0.isDragging = var1;
  770.    }
  771. }
  772.